class Solution
{
public:
    int countSubstrings(string s)
    {
        int n = s.size();
        int answer = 0;
        for (int i = 0; i < n; ++i)
        {
            int j = 0;
            while (i - j >= 0 && i + j < n && s[i - j] == s[i + j])
            {
                ++j;
                ++answer;
            }
            int k = 0;
            while (i - k >= 0 && i + 1 + k < n && s[i - k] == s[i + 1 + k])
            {
                ++k;
                ++answer;
            }
        }
        return answer;
    }
};